package com.ruoyi.kenuo.controller;


import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.RsaUtilClient;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.kenuo.domain.KernelUserEqu;
import com.ruoyi.kenuo.service.IMyUserService;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags="客户管理")
@RestController
@RequestMapping("/kenuo/client")
public class ClientController extends BaseController {


    @Autowired
    private ISysUserService userService;
    @Autowired
    private IMyUserService imuService;

    /***
     * 查询客户信息列表
     * @date 20230302
     * @author polo
     *
     */
    @GetMapping("/getClientList")
    public TableDataInfo getClientList(SysUser user)
    {
        startPage();
        List<SysUser> list = userService.getClientList(user);
        return getDataTable(list);
    }
    /***
     * 注销账号
     * @date 20230915
     * @author polo
     *
     */
    @PostMapping("/offUser")
    public AjaxResult offUser(@RequestBody SysUser user) throws Exception {
        String userName = user.getUserName();
        Long userId = user.getUserId();
        if(StringUtils.isEmpty(userName)){
            return AjaxResult.error("The paramete 'userName' is empty ");
        }else{
            userName = RsaUtilClient.decryptByPrivateKeyTwo("",userName);
            user.setUserName(userName);
        }
        if(ObjectUtil.isEmpty(userId)){
            return AjaxResult.error("The paramete 'userId' is empty ");
        }
        AjaxResult ar = imuService.offUser(user);
        return ar;
    }
}
